<form action="index.php?app=ome&ctl=admin_goods_cat&act=update" id="catEditor" method="post">
    <{area inject=".mainHead"}>
        <div class="finder-top clearfix">
            <div class="finder-title"><h3 class="head-title"><{t}>商品类别<{/t}><em class="num"><{t}>(共<{$tree_number}>条)<{/t}></em></h3></div>
        </div>
        <div class="gridlist-action">
            <{button label="添加分类" icon="btn_add.gif" onclick="W.page('index.php?app=ome&ctl=admin_goods_cat&act=addnew')" }>
            <{if $tree_number<=500}> <{button label="全部展开" id="showCat-handle" icon="btn_unfolded.gif" }> <{button label="全部收起" icon="btn_folded.gif" id="hideCat-handle" }><{/if}>
            &nbsp;
        </div>
        <div class='gridlist-head mainHead'>
            <div class='span-8' ><{t}>分类名称<{/t}></div>
            <div class='span-4'><{t}>类型<{/t}></div>
            <div class='span-2'><{t}>添加子类<{/t}></div>
            <div class='span-2'><{t}>编辑<{/t}></div>
            <div class='span-2'><{t}>删除<{/t}></div>
            <div class='span-2'><{t}>查看商品<{/t}></div>
            <div class='span-2'><{t}>预览<{/t}></div>
        </div>
    <{/area}>
    <div id="cat_tree" class='gridlist'> <{foreach from=$tree item=item name="item"}>
        <div depath="<{$item.step}>" class="clear_cat row" cid="<{$item.cat_id}>" pid="<{$item.pid}>">
            <div class='row-line'>
                <div class='span-8' style='text-align:left!important'>
                    <div  style="margin-left:<{$item.step*10}>px;text-align:left; padding-left:20px" ><{if $tree_number<=500}>
                        <{if $item.cls=='true'}>  <span style='width:12px;line-height:12px;margin:auto 4px;overflow:hidden;display:inline-block;padding:0;cursor:pointer'>  <{img src="bundle/handle-hide.gif" alt="收起子分类" title="收起子分类" class="handle-hide" app='desktop'}>
                        <{img src="bundle/handle-show.gif" alt="收起子分类" title="展开子分类" class="handle-show" app='desktop'}> </span> <{else}>
                        <{img src="bundle/blue-dot.gif"  app='desktop'}>
                        <{/if}>
                        <{/if}>
                        <{t}>排序<{/t}>
                        <input class="_x_ipt" type="number" size="2"  name="p_order[<{$item.cat_id}>]" value="<{$item.p_order}>" vtype="unsigned">
                        <span class="lnk" style="color:#369;" onClick='W.page("index.php?app=ome&ctl=admin_goods_cat&act=edit&p[0]=<{$item.cat_id}>")'><{$item.cat_name}></span></div>
                </div>
                <div class='span-4'><span class="quiet" style="padding:0 5px"><{if $item.type_name}>[<{$item.type_name}>]<{/if}></span></div>
                <div class='span-2'><{assign var="cat_id" value=$item.cat_id}><span class="opt" onClick='W.page("index.php?app=ome&ctl=admin_goods_cat&act=addnew&p[0]=<{$item.cat_id}>")'><{img src="bundle/addcate.gif" border="0" alt="添加子分类" app='desktop'}></span></div>
                <div class='span-2'><span class="opt" onClick="W.page('index.php?app=ome&ctl=admin_goods_cat&act=edit&p[0]=<{$item.cat_id}>')"><{img src="bundle/editcate.gif" border="0" alt="编辑"  app='desktop'}></span></div>
                <div class='span-2'><span class="opt" onclick="deleteRow('index.php?app=ome&ctl=admin_goods_cat&act=toRemove&p[0]=<{$item.cat_id}>',event)"><{img src="bundle/delecate.gif" border="0" alt="删除" app='desktop'}></span></div>
                <div class='span-2'><span class="opt" onclick='W.page("index.php?app=ome&ctl=admin_goods&act=index&filter[cat_id]=<{$item.link.cat_id.v}>")'><{img src="bundle/showcate.gif" border="0" alt="查看此分类下商品" app='desktop'}></span></div>
                <div class='span-2'><span class="opt" onclick="window.open('<{$item.url}>')"><{img src="bundle/zoom_btn.gif" border="0" alt="跳转前台查看该" app='desktop'}></span></div>
            </div>
        </div>
        <{/foreach}> </div>
    <{area inject=".mainFoot"}>
    <div class="footer">
        <div class="table-action">
            <{button class="btn-primary" label="保存排序" type="submit"  onclick="$('catEditor').fireEvent('submit',{stop:function(){}})"}>
        </div>
    </div>
    <{/area}>
</form>
<script>

function deleteRow(act,event){
e=$(new Event(event).stop().target);
     var row=e.getParent('.row');

    if(confirm('您确定要删除该分类？')){
        W.page(act,{
        method:'get',
        update:'messagebox',
        onComplete:function(re){

            if(re.contains('successSplash')){row.remove();}

            }
        });
    }
}
<{if $tree_number<=500}>
void function(){
   $E('#hideCat-handle').addEvent('click',function(){
    $ES('#cat_tree .clear_cat').each(function(e){
        if(e.get('depath')>1){
            e.setStyles({'display':'none'});
        }
    });
    $ES('#cat_tree .handle-hide').hide();
  });
    $E('#showCat-handle').addEvent('click',function(){

        $ES('#cat_tree .clear_cat').each(function(e){
            if(e.get('depath')>1){
                e.setStyles({'display':''});
            }
        });
        $ES('#cat_tree .handle-hide').show();
    });

    $('cat_tree').addEvent('click',function(e){

       if(!e.target.className.match(/handle-/i))return;


      var handle=$(e.stop().target);
            var eventRow=handle.getParent('.row');
            var visible=handle.hasClass('handle-show')?'':'none';
                if(visible=='none'){
                         handle.hide().getNext().show();
                    }else{
                         handle.hide().getPrevious().show();

                    }
            flode(eventRow,visible);

    });

    function flode(eventRow,visible){
            var cid=eventRow.get('cid');
            var pid=eventRow.get('pid');

            eventRow.getAllNext('div[pid='+cid+']').each(function(row){
                if(visible=='none'){
                    row.hide();
                    var obj=row.getElements('.span-8 img');
                    if(obj.length>1){
                        flode(row,visible);
                    }
                }else{
                    row.show();
                    var obj=row.getElements('.span-8 img');
                    if(obj.length>1){
                        var vis=(obj[0].getStyle('display')=='none'?'none':'inline');
                        flode(row,vis);
                    }
                }

            });
    }
}();
<{/if}>

</script>
